#include<stdio.h>

int main(void)
{
	int input,real,han,ten,one;
	scanf("%d",&input);
	
	han=input/100;
	ten=(input-100*han)/10;
	one=input-100*han-10*ten;
	if(han>4)
	{
		han-=1;
	}
	if(ten>4)
	{
		ten-=1;
	}
	if(one>4)
	{
		one-=1;
	}
	real=han*81+ten*9+one;
	
	printf("%d",real);
	
	return 0;
}
//
/*

*/
